package com.wswy.wzcx.widget.shadow;

import android.graphics.Path;

class ShapeUtils {

  static Path roundedRect(
      float left,float top,float right,float bottom,
      float tl,float tr,float br,float bl) {

    Path path =new Path();
    if (tl < 0) tl = 0f;
    if (tr < 0) tr = 0f;
    if (br < 0) br = 0f;
    if (bl < 0) bl = 0f;
    float width = right - left;
    float height = bottom - top;
    if (tl > Math.min(width, height) / 2) tl = Math.min(width, height) / 2;
    if (tr > Math.min(width, height) / 2) tr = Math.min(width, height) / 2;
    if (br > Math.min(width, height) / 2) br = Math.min(width, height) / 2;
    if (bl > Math.min(width, height) / 2) bl = Math.min(width, height) / 2;
//        val widthMinusCorners = width - 2 * rx
//        val heightMinusCorners = height - 2 * ry

    path.moveTo(right, top + tr);
    if (tr > 0)
      path.rQuadTo(0f, -tr, -tr, -tr);//top-right corner
    else {
      path.rLineTo(0f, -tr);
      path.rLineTo(-tr, 0f);
    }
    path.rLineTo(-(width - tr - tl), 0f);
    if (tl > 0)
      path.rQuadTo(-tl, 0f, -tl, tl); //top-left corner
    else {
      path.rLineTo(-tl, 0f);
      path.rLineTo(0f, tl);
    }
    path.rLineTo(0f, height - tl - bl);

    if (bl > 0)
      path.rQuadTo(0f, bl, bl, bl);//bottom-left corner
    else {
      path.rLineTo(0f, bl);
      path.rLineTo(bl, 0f);
    }

    path.rLineTo(width - bl - br, 0f);
    if (br > 0)
      path.rQuadTo(br, 0f, br, -br); //bottom-right corner
    else {
      path.rLineTo(br, 0f);
      path.rLineTo(0f, -br);
    }

    path.rLineTo(0f, -(height - br - tr));

    path.close();//Given close, last lineto can be removed.

    return path;
  }

}
